<?
if($_SESSION[ "authority"]!="admin"){
   include "../NIV/checkauthority.php"; 
}else{
$id=isset($_REQUEST["id"])?$_REQUEST["id"]:"Vietnam";
$group=isset($_REQUEST["groupby"])?$_REQUEST["groupby"]:"''";
switch ($group){
    case "Name":
        $groupby="LEFT(`name`,1)";
        break;
    case "Type":
        $groupby="`type`";
        break;
    case "Country":
        $groupby="`country`";
        break;
    default :
        $groupby="''";
}
$nivOrdata=$TemplateModule->getOrganizationByCountry($id,$groupby);
?>
<table class="table-data" style="width: 959px;margin-top: 12px">
    <tr>
        <th></th>
        <th>No.</th>
        <th style="min-width: 180px">
            <img style="float: left;  padding-right: 4px;<?=$group!="Name"?"opacity: 0.25;cursor: pointer;":""?>" src="../images/stock_group_cells (1).png"
                 title="Group by Name"
                 onclick="organ_groupby('<?=$id?>','Name');"
                 />
            Organization(Name)
        </th>
        <th  style="width: 80px">
            <img style="float: left;padding-right: 4px;<?=$group!="Type"?"opacity: 0.25;cursor: pointer;":""?>" src="../images/stock_group_cells (1).png"
                 title="Group by Type"
                 onclick="organ_groupby('<?=$id?>','Type');"
                 />
            Type
        </th>
        <th>Country</th>
        <th>Province</th>
        <th>Mail</th>
        <th>Address</th>
    </tr>

<?
//organization
$n=0;
$gr="";
if($nivOrdata==null){
    echo "<tr><td colspan='8' style='text-align:center'>No data to display</td></tr>";
}else foreach ($nivOrdata as $r){
    $n++;
    if(strtolower(str_replace(" ", "", $gr))!=strtolower(str_replace(" ", "",$r["group"]))){
        $gr=$r["group"];
        echo "<tr><td colspan='8' ><b>".$group." : ".$r["group"]."</b></td></tr>";
    }
?>
    <tr>
        <td></td>
        <td><?=$n?></td>
        <td><?=$r["name"]?></td>
        <td><pre><?=$r["type"]?></pre></td>
        <td><?=$r["country"]?></td>
        <td><?=$r["province"]?></td>
        <td><pre><?=$r["mail"]?></pre></td>
        <td><pre><?=$r["address"]?></pre></td>
    </tr>
<?
}
?>
</table>
<?
}
?>